package cn.jlonely.xyhx.app.mapper;

import cn.jlonely.xyhx.pojo.Comments;
import cn.jlonely.xyhx.pojo.Ranking;
import cn.jlonely.xyhx.pojo.vo.CommentsVo;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AppRankingMapper {

    /**
     * 获取所有榜单
     *
     * @param userId
     * @param topic
     * @param id
     * @return
     */
//    @Select("SELECT * FROM ranking_table WHERE topic LIKE CONCAT('%', #{topic}, '%') OR ranking_id = #{id} ORDER BY ranking_status ASC")
//    @Results({
//            @Result(property = "id", column = "ranking_id")
//    })
//    //List<Ranking> getRankingInfoAll(String topic, Integer id);
    List<Ranking> getRankingInfoAll(@Param("userId")Integer userId, @Param("topic") String topic, @Param("id") Integer id);


    /**
     * 创建收藏
     * @param userId
     * @param rankingId
     */
    @Insert("insert into favorites (user_id,ranking_id) values(#{userId},#{rankingId})")
    void createFavorite(Integer userId, Integer rankingId);

    /**
     * 取消收藏
     * @param userId
     * @param rankingId
     */
    @Delete("DELETE FROM favorites WHERE user_id = #{userId} AND ranking_id = #{rankingId}")
    void deleteFavorite(Integer userId, Integer rankingId);

    /**
     * 查询所有收藏
     * @param userId
     * @return
     */
    List<Ranking> getFavoriteAll(Integer userId);

    /**
     * 查询所有投票记录
     * @param userId
     * @return
     */
    List<Ranking> getHistoryVitoAll(Integer userId);

    /**
     * 查询所有评论
     * @param rankingId
     * @return
     */

    List<Comments> getCommentsAll(Integer rankingId);

    /**
     * 创建评论
     * @param comments
     */
    @Insert("insert into comments (ranking_id,user_id,content) values(#{rankingId},#{userId},#{content})")
    void createComments(Comments comments);

    /**
     * 查看历史评论
     * @param userId
     * @return
     */
    List<CommentsVo> getHistoryComments(Integer userId);
}
